package com.neusoft.approveserver.service.impl;

import com.neusoft.approveserver.dto.RespBean;
import com.neusoft.approveserver.entity.Chance;
import com.neusoft.approveserver.mapper.ChanceMapper;
import com.neusoft.approveserver.service.IChanceService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Calendar;
import java.util.Date;

/**
 * <p>
 * 主机会表 服务实现类
 * </p>
 *
 * @author liuxp
 * @since 2021-07-12
 */
@Service
public class ChanceServiceImpl extends ServiceImpl<ChanceMapper, Chance> implements IChanceService {
    @Autowired
    ChanceMapper chanceMapper;

    @Override
    public RespBean generateChanceCode(Integer id) {
        Chance chance = chanceMapper.selectById(id);
        Calendar rightNow = Calendar.getInstance();
        int year = rightNow.get(Calendar.YEAR);
        String chanceCode = "" + year;
        if(id >= 1000){
            chanceCode += id;
        }else if(id >= 100){
            chanceCode += "0" + id;
        }else if(id >= 10){
            chanceCode += "00" + id;
        }else{
            chanceCode += "000" + id;
        }
        chance.setChanceCode(chanceCode);
        RespBean respBean = RespBean.ok(200, "Chance code generated successfully!");
        chanceMapper.updateById(chance);
        return respBean;
    }
}
